package com.she.olympic;

import net.emome.hamiapps.sdk.ForwardActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

import com.samsung.zirconia.LicenseCheckListener;
import com.samsung.zirconia.Zirconia;

public class SamsungCheckLicense extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Handler handler = new Handler();
		TextView tv = new TextView(this);
		tv.setText("This is application for Zirconia!\nPlease hold on while verifying the license...");
		setContentView(tv); // setContentView(R.layout.main);

		/*
		 * 创建对象 第一个参数是正在执行的应用程序的活动对象。
		 */
		Zirconia zirconia = new Zirconia(this);
		/*
		 * 创建监听器对象 将监听器对象注册到 Zirconia 对象 检查许可证。
		 */
		MyLicenseCheckListener listener = new MyLicenseCheckListener();
		listener.ownerHandler = handler;
		listener.ownerTextView = tv;
		zirconia.setLicenseCheckListener(listener);
		zirconia.checkLicense(false, false);
	}
	
	/* 接收许可证验证和查询结果的监听器类型 */
	class MyLicenseCheckListener implements LicenseCheckListener {
		/* 许可证验证和查询结果正常时 */
		@Override
		public void licenseCheckedAsValid() {
			Log.d("ZirconiaTest", "License is valid");
			ownerHandler.post(new Runnable() {
				public void run() {
					SamsungCheckLicense.this.finish();
					Intent it = new Intent();
					it.setClass(SamsungCheckLicense.this, SplashScreenActivity.class);
					startActivity(it);
					System.gc();
				}
			});
		}

		/* 许可证验证和查询结果不正常时 */
		@Override
		public void licenseCheckedAsInvalid() {
			Log.d("ZirconiaTest", "License is invalid");
			ownerHandler.post(new Runnable() {
				public void run() {
					SamsungCheckLicense.this.finish();
					android.os.Process.killProcess(android.os.Process.myPid());
				}
			});
		}

		Handler ownerHandler;
		TextView ownerTextView;
	}
}

